package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.acticle.domain.FlightScheduled;
import cn.wolfcode.luowowo.acticle.query.FlightScheduledQuery;
import cn.wolfcode.luowowo.acticle.service.IFlightScheduledService;
import cn.wolfcode.luowowo.article.mapper.FlightScheduledMapper;
import cn.wolfcode.luowowo.common.exception.LogicException;
import cn.wolfcode.luowowo.common.util.AssertUtil;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;

import java.util.List;

@Service
public class FlightScheduledServiceImpl implements IFlightScheduledService {

    @Autowired
    private FlightScheduledMapper flightScheduledMapper;

    @Override
    public List<FlightScheduled> listFlightScheduledForSearch(FlightScheduledQuery qo) throws LogicException {
        AssertUtil.hasLength(qo.getOrgCity(),"出发地不能为空");
        AssertUtil.hasLength(qo.getDstCity(),"目的地不能为空");
        if(qo.getDstCity().equals(qo.getOrgCity())){
            throw new LogicException("出发地和目的地不能相同");
        }

        return flightScheduledMapper.selectFlightScheduledByQo(qo);
    }

    @Override
    public PageInfo query(FlightScheduledQuery qo) throws LogicException{
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        return new PageInfo(flightScheduledMapper.selectFlightScheduledByQo(qo));
    }

    @Override
    public FlightScheduled getTicket(Long pid) {
        return flightScheduledMapper.selectByPrimaryKey(pid);
    }
}
